Skip to content

Conversation

cyrgani
Copy link
Contributor

@cyrgani cyrgani commented Oct 5, 2025

Several smaller cleanups to proc_macro. Commits 1 and 3 seem pretty trivial to me, commit 2 might be worth it or not.

Followup to #147166.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 5, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@petrochenkov
Copy link
Contributor

The second commit makes sense to me, the arena's use is limited, and if the &mut self doesn't cause any inconvenience, then it's better to use it, because it's simpler.

self.grow(bytes);
if let Some(a) = self.alloc_raw_without_grow(bytes) {
// SAFETY: the lifetime is extended here, but then constrained again in `alloc_str`.
return unsafe { &mut *(a as *mut _) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove the internal mutability without this change?
I'm not sure how it's related to the rest of the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unsafe is unfortunately needed to avoid an error[E0499]: cannot borrow *self as mutable more than once at a time. (This would be fixed with -Zpolonius.)
I removed the loop because grow will always produce enough space to hold the data, so it seemed a bit clearer to me this way (with the old code, I thought at first that grow might need to be called many times).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the cells then.

The loop can still be refactored to if let or unwrap_or_else though.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants